package com.shiliao.app.activity.interlocution.dialog;

import android.app.Activity;
import android.content.Context;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.TextView;

import com.shiliao.app.R;
import com.yimei.framework.ui.dilaog.AnimationType;
import com.yimei.framework.ui.dilaog.YimeiBaseDialog;

import org.w3c.dom.Text;


/**
 * Created by yinzhiqiang on 2017/9/11.
 */

public class QuestionDialog extends YimeiBaseDialog {

    private TextView mComfirm;
    private TextView mCancel;
    private EditText mContent;
    private TextView title;
    /**
     * 构造函数.
     *
     * @param activity context
     */
    public QuestionDialog(Activity activity) {
        super(activity);
        //  getLayoutInflater().inflate(R.layout.dialog, null);
        mContainerView = getLayoutInflater().inflate(R.layout.dialog_question, null);
        mComfirm = (TextView) mContainerView.findViewById(R.id.tv_comfirm);
        mCancel = (TextView) mContainerView.findViewById(R.id.tv_cancel);
        mContent = (EditText) mContainerView.findViewById(R.id.ed_content);
        title=mContainerView.findViewById(R.id.tv_title);
        mWindow.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER);
        mWindow.setWindowAnimations(mAnimations[AnimationType.TOAST_FADE
                .getValue()]);
        mCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mDialog.dismiss();
            }
        });
    }

    @Override
    public void show(boolean isAutoDismiss) {
        super.show(isAutoDismiss);
        WindowManager.LayoutParams layoutParams = mDialog.getWindow().getAttributes();
        layoutParams.gravity = Gravity.CENTER;
        mDialog.getWindow().setAttributes(layoutParams);
    }

    public void setComfirn(View.OnClickListener listener) {
        if (mActivity != null && mComfirm != null) {
            mComfirm.setOnClickListener(listener);
        }

    }

    public String getContent() {
        return mContent.getText().toString().trim();
    }

    public void hideKeyboard() {
        // 影藏软键盘
        if (mContent != null && mActivity != null) {
            InputMethodManager imm = (InputMethodManager) mActivity
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(mContent.getWindowToken(), 0);
        }

    }

    public void showKeyBoard() {
        // 设置软件盘显示，和alert dialog有冲突
        if (mDialog != null) {
            mDialog.getWindow().clearFlags(
                    WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                            | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
            mDialog.getWindow().setSoftInputMode(
                    WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
        }
    }

    public void setHintText(String text){
        if (!TextUtils.isEmpty(text)){
            mContent.setHint(text);
        }
    }

    public void setTitleText(String titleText){
        if (!TextUtils.isEmpty(titleText)){
            title.setText(titleText);
        }
    }

}
